package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.service.UserSetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/setmeal")
@Slf4j
public class UserSetMealController {

    @Autowired
    private UserSetmealService userSetmealService;

    /**
     * 根据id查套餐
     * @param categoryId
     * @return
     */
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> getById(@PathVariable Long categoryId) {
        List<DishItemVO> dishItemVO = userSetmealService.getById(categoryId);
       return Result.success(dishItemVO);
    }


    @Cacheable(value = "setmealCache",key = "#categoryId")
    @GetMapping("/list")
    public Result<List<Setmeal>> list(Long categoryId) {
        Setmeal setmeal = new Setmeal();
        setmeal.setCategoryId(categoryId);
//        setmeal.setStatus(StatusConstant.ENABLE);
        List<Setmeal> list = userSetmealService.list(setmeal);
        return Result.success(list);

    }

}
